fn main() {
    println!("结构体 struct");

    #[derive(Debug)]
    struct Pair(i32, i32);
    println!("元组结构体 Pair(i32, i32):{:?}", Pair(3, 4));

    #[allow(dead_code)] // x,y 不使用的警告
    #[derive(Debug)]
    struct Point {
        x: f32,
        y: f32,
    }
    println!("struct Point: {:?}", Point { x: 1.2, y: 2.3 });

    // Rectangle 两边确定一个方形
    #[derive(Debug)]
    #[allow(dead_code)]
    struct Rectangle {
        top_left: Point,
        bottom_right: Point,
    }
    impl Rectangle {
        fn rect_area(&self) -> f32 {
            (self.bottom_right.x - self.top_left.x) * (self.top_left.y - self.bottom_right.y)
        }
    }

    let area = Rectangle {
        top_left: Point { x: 3f32, y: 3f32 },
        bottom_right: Point { x: 6f32, y: 1f32 },
    }
    .rect_area();
    println!("计算面积的方法 rect_area: {}", area);

    // sqare 返回一个方形
    fn sqare(p: &Point, long_width: f32) -> Rectangle {
        Rectangle {
            top_left: Point { x: p.x, y: p.y },
            bottom_right: Point {
                x: p.x + long_width,
                y: p.y - long_width,
            },
        }
    }
    println!(
        "函数 sqare 返回一个方形: {:?}",
        sqare(&Point { x: 3f32, y: 3f32 }, 3f32)
    );
}
